/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CategoriesPanel.java
 *
 * Created on 2011-4-23, 16:57:41
 */
package com.iduxs.collect.frame.system;

import com.iduxs.collect.utils.Utility;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author riecard
 */
public class CategoriesPanel extends javax.swing.JPanel {

    /** Creates new form CategoriesPanel */
    public CategoriesPanel() {
        initComponents();
        init();
    }
    
    private void init() {
        Categories c = new Categories();
        try {
            Utility.readXMLFile("Categories.xml", c);
            categoriesText.setText(c.getCategories());
            defaultCategoriesText.setText(c.getDefaultCategories());
            defaultSubCategoriesText.setText(c.getDefaultSubCategories());
            subCategoriesText.setText(c.getSubCategories());
            useDefaultCategoriesBox.setSelected(c.getUseDefaultCategories());
            useDefaultSubCategoriesBox.setSelected(c.getUseSubDefaultCategories());
        } catch (Exception ex) {
            Logger.getLogger(CategoriesPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        useDefaultCategoriesBox = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        defaultCategoriesText = new javax.swing.JTextField();
        jScrollPanel2 = new javax.swing.JScrollPane();
        categoriesText = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        useDefaultSubCategoriesBox = new javax.swing.JCheckBox();
        jLabel4 = new javax.swing.JLabel();
        defaultSubCategoriesText = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        subCategoriesText = new javax.swing.JTextArea();
        saveButton = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jLabel1.setText("大类对应：");

        useDefaultCategoriesBox.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        useDefaultCategoriesBox.setText("不使用默认大类");

        jLabel2.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jLabel2.setText("默认大类：");

        defaultCategoriesText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                defaultCategoriesTextActionPerformed(evt);
            }
        });

        categoriesText.setColumns(20);
        categoriesText.setRows(5);
        jScrollPanel2.setViewportView(categoriesText);

        jLabel3.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jLabel3.setText("小类对应：");

        useDefaultSubCategoriesBox.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        useDefaultSubCategoriesBox.setText("不使用默认小类");

        jLabel4.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        jLabel4.setText("默认小类：");

        subCategoriesText.setColumns(20);
        subCategoriesText.setRows(5);
        jScrollPane1.setViewportView(subCategoriesText);

        saveButton.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        saveButton.setText("确定");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        resetButton.setFont(new java.awt.Font("宋体", 0, 12)); // NOI18N
        resetButton.setText("取消");
        resetButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(saveButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(resetButton)
                        .add(9, 9, 9))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(layout.createSequentialGroup()
                            .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(71, 71, 71)
                            .add(useDefaultCategoriesBox)
                            .add(45, 45, 45)
                            .add(jLabel2)
                            .add(2, 2, 2)
                            .add(defaultCategoriesText))
                        .add(jScrollPanel2)
                        .add(layout.createSequentialGroup()
                            .add(jLabel3)
                            .add(100, 100, 100)
                            .add(useDefaultSubCategoriesBox)
                            .add(39, 39, 39)
                            .add(jLabel4)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(defaultSubCategoriesText))
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 613, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(useDefaultCategoriesBox)
                    .add(jLabel2)
                    .add(defaultCategoriesText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(useDefaultSubCategoriesBox)
                    .add(jLabel4)
                    .add(defaultSubCategoriesText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(resetButton)
                    .add(saveButton))
                .add(24, 24, 24))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void defaultCategoriesTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultCategoriesTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_defaultCategoriesTextActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        System.out.println("saveButtonActionPerformed");
        Categories c = new Categories();
        c.setCategories(categoriesText.getText().trim());
        c.setDefaultCategories(defaultCategoriesText.getText().trim());
        c.setDefaultSubCategories(defaultSubCategoriesText.getText().trim());
        c.setSubCategories(subCategoriesText.getText().trim());
        c.setUseDefaultCategories(useDefaultCategoriesBox.isSelected());
        c.setUseSubDefaultCategories(useDefaultSubCategoriesBox.isSelected());
        try {
            Utility.writeXMLFile("Categories.xml", c);
        } catch (Exception ex) {
            Logger.getLogger(CategoriesPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_saveButtonActionPerformed

    private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_resetButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea categoriesText;
    private javax.swing.JTextField defaultCategoriesText;
    private javax.swing.JTextField defaultSubCategoriesText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPanel2;
    private javax.swing.JButton resetButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JTextArea subCategoriesText;
    private javax.swing.JCheckBox useDefaultCategoriesBox;
    private javax.swing.JCheckBox useDefaultSubCategoriesBox;
    // End of variables declaration//GEN-END:variables
}
